<?php

/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

	$arr_user_id = explode(',',$this->item->job_author);
	$user_name = '';
	for ($i=0;$i<count($arr_user_id);$i++)
	if ($arr_user_id[$i])
	{
		$profile = getCustomerProfile($arr_user_id[$i]);
		if( ! isset($profile->company) ){
			$user = JFactory::getUser($arr_user_id[$i]);
			$profile->company = $user->name;
		}
		if ($user_name)
			$user_name .= ','.$profile->company;
		else 
			$user_name .= $profile->company;
	}
	
?>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
user_name = '<?php echo $user_name; ?>';
user_id = '<?php echo $this->item->job_author; ?>';
function validate()
{
	form = document.jobalertForm;
	
	if (form.title.value.trim()==''){
		alert('<?php echo JText::_("Title could not be empty"); ?>');
	}
	else if(form.keyword.value.trim()!='' && form.keyword.value.trim().length<3){
		alert('<?php echo JText::_("Minimum length of keyword must be at least 3 characters"); ?>');
		form.keyword.focus();
	}
	else{
		form.submit();
	}
}

function checkbox_clicked(obj,checkbox_type,index)
{	
	if (checkbox_type=='category'){		
		for (i=index;i<child_category[obj.value].length;i++)
		{
			ele = document.getElementById(checkbox_type+'_'+child_category[obj.value][i]);
			ele.checked = obj.checked;
			if (child_category[ele.value].length>0)
			{
				temp = i;
				checkbox_clicked(ele,checkbox_type,0);
				i = temp;
			}
		}
	}else
		for (i=index;i<child_location[obj.value].length;i++)
		{
			ele = document.getElementById(checkbox_type+'_'+child_location[obj.value][i]);
			ele.checked = obj.checked;
			if (child_location[ele.value].length>0) 
			{
				temp = i;
				checkbox_clicked(ele,checkbox_type,0);
				i = temp;
			}
		}
		return index;
}

function assign_user(user_id,user_name)
{
	document.getElementById('job_author').value = user_id;
	var temp_userid = user_id;
	arr_user_id = new Array();
	count_span = 0;
	while (user_id.indexOf(',')!=-1)
	{
		count_span++;
		temp = user_id.substring(0,user_id.indexOf(','));
		user_id = user_id.substring(user_id.indexOf(',') + 1,user_id.length);
		arr_user_id[count_span] = temp;
	}
	arr_user_id[count_span + 1] = user_id;
	user_id = temp_userid;
	
	document.getElementById('job_author').value = user_id;	
	var s_selected_employer = document.getElementById('s_selected_employer');
	s_selected_employer.innerHTML = '';
	var display_text = '';
	count_span = 0;
	while (user_name.indexOf(',')!=-1)
	{
		count_span ++;
		temp = user_name.substring(0,user_name.indexOf(','));
		user_name = user_name.substring(user_name.indexOf(',') + 1,user_name.length);
		display_text += '<span id="selection'+count_span + '">' + temp + '<a href="javascript:void(0)" onclick="remove_emp('+arr_user_id[count_span] +',\'selection'+count_span+'\')">'+'<img src="' + '<?php echo JURI::root(); ?>' + 'components/com_jajobboard/images/del.gif" alt="Delete" />'+'</a>' + '</span>';
	}
	count_span ++;
	display_text += '<span id="selection'+count_span + '">' + user_name + '<a href="javascript:void(0)" onclick="remove_emp('+arr_user_id[count_span] +',\'selection'+count_span+'\')">'+'<img src="' + '<?php echo JURI::root(); ?>' + 'components/com_jajobboard/images/del.gif" alt="Delete" />'+'</a>' + '</span>';
	
	s_selected_employer.innerHTML  = display_text;
	if (document.getElementById('sbox-window'))
		document.getElementById('sbox-window').close();
}	
function cancel_select_employer()
{
	document.getElementById('sbox-window').close();
}

function remove_emp(user_id,obj_id)
{
	obj = document.getElementById(obj_id);
	obj.innerHTML = '';
	select_user_id = document.getElementById('job_author').value;
	select_user_id = select_user_id.replace(','+user_id,'');
	select_user_id = select_user_id.replace(user_id,'');
	
	document.getElementById('job_author').value = select_user_id;
}

/* ]]> */
</script>
<style>
.clsCategory {
	max-height: 200px; overflow: auto; width:270px;
}
.clsLocation {
	max-height: 200px; overflow: auto;width:270px;
}
</style>
<?php
defined('_JEXEC') or die('Retricted Access');
$url = $mainframe->isAdmin() ? $mainframe->getSiteURL() : JURI::base();
JFilterOutput::objectHTMLSafe( $this->item );
JHTML::_('behavior.tooltip');
?>
<?php JHTML::_('behavior.modal', 'a.modal'); ?>
<?php 
	global $jbconfig;
	global  $option;
	$user = JFactory::getUser();
	
?>


<div id="jobboard-content">
	<h3>
		<?php echo JText::_("Job alert and saved search"); ?>
	</h3>
 	<form name="jobalertForm" action="<?php echo JURI::root();?>index.php" method="post" enctype="multipart/form-data">
 	<div class="moduletable job-alert">
 		<h3><?php echo JText::_('Filter information') ?></h3>
		<table class="tabledata">
		
			
			<tr class="sectiontableentry1">
				<td>
					<label for="title"><?php echo JText::_("Job search title"); ?></label>
				</td>
				<td>
					<input size="50" type="text" name="title" value="<?php echo $this->item->title; ?>" id="title" /><font color="Red">*</font>
				</td>
			</tr>
			<tr class="sectiontableentry2">
				<td>
					<label for="keyword"><?php echo JText::_("Find keywords"); ?></label>
				</td>
				<td>
					<input size="50" type="text" name="keyword" value="<?php echo $this->item->keyword; ?>" id="keyword" />
					<span class="editlinktip hasTip" title="<b><?php echo JText::_( 'Keyword' ) ?></b>:<br /><?php echo JText::_('Please insert a specific tittle (eg. Chief Accountant, Marketing manager) into keyword box to refine your results')?>"><img border="0" alt="Tooltip" src="<?php echo $url; ?>/includes/js/ThemeOffice/tooltip.png"/></span>
				</td>
			</tr>
			<tr class="sectiontableentry1">
				<td>
					<label><?php echo JText::_("Job must match"); ?></label>
				</td>
				<td>
					<input type="radio" <?php echo $this->item->keyword_option==1?'checked="checked"':''; ?> name="keyword_option" value="1" /><label><?php echo JText::_("Any of my keyword"); ?></label><br />
					<input type="radio" <?php echo $this->item->keyword_option==2?'checked="checked"':''; ?> name="keyword_option" value="2" /><label><?php echo JText::_("All of my keyword"); ?></label>
					<span class="editlinktip hasTip" title="<b><?php echo JText::_( 'Keyword option' ) ?></b>:<br /><?php echo JText::_('* <strong>Any of my keywords</strong>: search by <strong>any</strong> words that you enter in the keyword  section.<br />e.g. with  keyword: <strong>Sales Manager</strong>, the system  will find all jobs that have <strong>Sales</strong> or <strong>Manager</strong> or <strong>Sales Manager </strong>as a whole phrase<p>* <strong>All of my keywords</strong>: search by <strong>all</strong> words that you enter in the keyword  section.<br />e.g. with  keyword <strong>Sales Manager</strong> the system  will find all jobs that have the whole  phrase <strong>Sales Manager</strong> such as General  Sales Manger or Regional Sales Manger</p><p>* <strong>This exact phrase</strong>: search by the <strong>exact keywords</strong> that you enter in the  keyword section.<br />e.g. with keyword <strong>enterprising,</strong> the system will find all jobs that have the exact  word <strong>enterprising</strong> and will ignore  words like <strong>enterprise</strong> or <strong>enter</strong>.</p>')?>"><img border="0" alt="Tooltip" src="<?php echo $url; ?>/includes/js/ThemeOffice/tooltip.png"/></span><br />
					<input type="radio" <?php echo $this->item->keyword_option==3?'checked="checked"':''; ?> name="keyword_option" value="3" /><label><?php echo JText::_("This exact phrase"); ?></label>
				</td>
			</tr>
			<tr class="sectiontableentry2">
				<td>
					<label><?php echo JText::_("Categories"); ?></label>
				</td>
				<td>
					<?php echo $this->objCategory; ?>
				</td>
			</tr>
			<tr class="sectiontableentry1">
				<td>
					<label><?php echo JText::_("Locations"); ?></label>
				</td>
				<td>
					<?php echo $this->objLocation; ?>
				</td>
			</tr>
			<!--<tr class="sectiontableentry2">
				<td>
					<label><?php echo JText::_("Radius (km)"); ?></label>
				</td>
				<td>
					<?php echo $this->objJobDistance; ?>
				</td>
			</tr>-->
			
		<!--</table>-->
		
		<!--<table>-->
			
			<!--<tr class="sectiontableentry1">
				<td width="20%">
					<label for="sal_min"><?php echo JText::_('Salary Minimum'); ?></label>
				</td>
				<td width="30%">	
					
					<input onkeyup="NumberOnly1(this)" type="text" name="sal_min" style="width:150px;" value="<?php echo $this->item->sal_min; ?>" id="sal_min" />
				</td>
				<td width="20%"><label for="sal_max"><?php echo JText::_('Salary Maximum'); ?></label></td>
				<td width="30%">	
					<input onkeyup="NumberOnly1(this)" type="text" name="sal_max" style="width:150px;" value="<?php echo $this->item->sal_max; ?>" id="sal_max" />
				</td>
			</tr>-->
			<tr class="sectiontableentry1">
				<td><label for="job_type"><?php echo JText::_('Job type'); ?></label></td>
				<td>
					<?php echo $this->objJobType; ?>
					
				</td>
				
			</tr>
			<tr class="sectiontableentry2">
				<td><label for="posted_date"><?php echo JText::_("Job Posted In The Last"); ?></label></td>	
				<td>
					
					<?php echo $this->objPostedDate; ?>
				</td>
			</tr>
			<tr>
				<td class="sectiontableentry1"><?php echo JText::_('Job posted by'); ?></td>
				<td>
					<span id="s_selected_employer"></span>
					<a class="modal" rel="{handler: 'iframe', size: {x: 850, y: 475}}" href="index.php?option=com_jajobboard&view=jajobalerts&layout=element_user&tmpl=component&selected=<?php echo $this->item->job_author; ?>&limitstart=<?php echo JRequest::getVar('limitstart',0); ?>" title="Select an User">(<?php echo JText::_('Select employer'); ?>)</a>
					<input type="hidden" size="70" name="job_author" id="job_author" value="<?php echo $this->item->job_author; ?>" />
				</td>
			</tr>
		</table>
		<h3>&nbsp;</h3>
		<table>
			<tr class="sectiontableentry2">
				<td>
					<label for="sendmail_duration"><?php echo 	JText::_('How often do you want to receive suitable jobs via email?'); ?></label>
				</td>
					
				<td>
					<?php echo $this->objSendMailDuration; ?>
				</td>
			</tr>
		
	    </table>
	    <table class="tabledata"> 
	        <tr>
	            <td>
	            	<div align="center" style="width:100%;">
		                <input class="button" type="button" onclick="validate()" value="<?php echo JText::_('Save'); ?>" />
	            		<input class="button" type="button" onclick="javascript:window.history.go(-1);" value="<?php echo JText::_('Cancel'); ?>" />
            		</div>
	            </td>
	        </tr>
	    </table>	
	    <input type="hidden" name="cid[]" value="<?php echo $this->item->id; ?>" />
	    <input type="hidden" name="user_id" value="<?php echo $user->id; ?>" />
		<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
		<input type="hidden" name="view" value="jajobalerts" />
		<input type="hidden" name="task" value="save" />
		<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />	
		<?php echo JHTML::_( 'form.token' ); ?>	
	</div>			
 	</form> 
</div>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
if (user_id)
	assign_user(user_id,user_name);

/* ]]> */
</script>